package com.ztz.mynewdemo.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

/**
 * Created by wqewqe on 2017/12/18.
 */

public abstract class BaseFragment extends Fragment {
    protected boolean isVisibleToUser=false;
    protected boolean isViewInit=false;
    protected boolean isInitData=false;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        isViewInit=true;
        requestData();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        this.isVisibleToUser=isVisibleToUser;
        requestData();
    }

    protected abstract void getData();

    private void requestData() {
        if(isViewInit&&isVisibleToUser&&!isInitData)
        {
            getData();
            isInitData=true;
        }
    }
}
